Skip to content

feat: use XDG_DATA_HOME for Flatpak data directory - #1369

Draft
sneurlax wants to merge 11 commits into
stagingfrom
feat/1249-flatpak-data-dir
Draft

sneurlax wants to merge 11 commits into
stagingfrom
feat/1249-flatpak-data-dir

Conversation

@sneurlax

@sneurlax sneurlax commented May 27, 2026 •

Copy link
Copy Markdown
Member

closes #1249

Refresh review (2026-11-10)

Refresh review keeps the latest migration flow (rename when possible; otherwise copy, verify, publish, then resume legacy cleanup) and serializes first-launch migration with an XDG sibling lock, including when Hive has not created dbinfo.lock. A cross-process regression test verifies only one migration proceeds and the wallet data is preserved. Flatpak manifests retain the required :create permission.

Checks: migration, environment, and override tests (14 passed); targeted flutter analyze clean.

Comment thread lib/main.dart Outdated
Comment on lines +102 to +139
} else if (Platform.isLinux) {
// Flatpak detection: use XDG_DATA_HOME instead of ~/.stackwallet.
final flatpakId = Platform.environment['FLATPAK_ID'];
if (flatpakId != null || File('/.flatpak-info').existsSync()) {
// Resolve the persistent data root. Prefer XDG_DATA_HOME when set.
// Otherwise fall back to $HOME/.local/share, but only if HOME is
// available. If neither is set we leave the data dir unchanged and
// let StackFileSystem use its default, rather than crashing.
final home = Platform.environment['HOME'];
final xdgDataHome = Platform.environment['XDG_DATA_HOME'] ??
(home != null ? path.join(home, '.local', 'share') : null);

if (xdgDataHome != null) {
final flatpakDataDir =
path.join(xdgDataHome, AppConfig.appDefaultDataDirName);

// Migration: move legacy data from $HOME/.stackwallet into the new
// location, but only when the legacy dir exists and the new one does
// not. Best-effort: never crash if the move fails.
if (home != null) {
final legacyDir = Directory(
path.join(home, '.${AppConfig.appDefaultDataDirName}'),
);
final newDir = Directory(flatpakDataDir);
if (legacyDir.existsSync() && !newDir.existsSync()) {
try {
await Directory(xdgDataHome).create(recursive: true);
await legacyDir.rename(newDir.path);
} catch (_) {
// If rename fails (e.g. different filesystem), fall back to
// using the new path anyway. The user can manually move data.
}
}
}

StackFileSystem.setDesktopOverrideDir(flatpakDataDir);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks setDesktopOverrideDir

Comment thread lib/utilities/stack_file_system.dart Outdated
// location or the -d launch flag) keep logs under that persistent root
// so they follow the data directory rather than landing in the
// application documents directory.
if (_overrideDesktopDirPath != null) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whole file needs different changes.

Although I do agree the logs dir currently has some issues re _overrideDesktopDirPath

@codecov

codecov Bot commented May 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.03401% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.01%. Comparing base (9ce80be) to head (ff7f921).
⚠️ Report is 1 commits behind head on staging.

Files with missing lines Patch % Lines
lib/utilities/flatpak_data_directory.dart 84.73% 20 Missing ⚠️
lib/utilities/stack_file_system.dart 87.50% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           staging    #1369      +/-   ##
===========================================
+ Coverage    13.92%   14.01%   +0.09%     
===========================================
  Files         1139     1140       +1     
  Lines       114707   114849     +142     
===========================================
+ Hits         15976    16100     +124     
- Misses       98731    98749      +18     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sneurlax

Copy link
Copy Markdown
Member Author

Converting to draft pending changes in response to the reviews and requested changes above

@sneurlax
sneurlax marked this pull request as draft August 20, 2026 18:56
Inside Flatpak the data root becomes $XDG_DATA_HOME/<app> instead of
~/.<app>, so it lives in the sandbox's own persistent directory.

Existing data is migrated once per process, before Hive opens: lock the
legacy Hive db, copy the tree to <root>.migrating, flush it, verify every
file by SHA-256, write a completion marker and rename it into place.
Legacy data is never modified or deleted and any failure falls back to
it, so the manifests keep --filesystem=~/.<app> to keep that fallback
readable. The -d launch flag still takes precedence over all of this.

closes #1249
@sneurlax
sneurlax force-pushed the feat/1249-flatpak-data-dir branch from 495d0af to d4b7ab9 Compare August 24, 2026 21:31
@sneurlax

sneurlax commented Oct 7, 2026

Copy link
Copy Markdown
Member Author

#1430 fixed the same "data doesn't persist" symptom the opposite way, keeping data in the home folder outside the sandbox with --filesystem=~/.:create. We need to pick one approach. If #1369 stays, it should move the old data folder rather than copy it, or a password reset (#1455) leaves the old copy behind.

Inside Flatpak the data root becomes $XDG_DATA_HOME/<app> instead of
~/.<app>, so it lives in the sandbox's own persistent directory.

Existing data is migrated once per process, before Hive opens: lock the
legacy Hive db, copy the tree to <root>.migrating, flush it, verify every
file by SHA-256, write a completion marker and rename it into place.
Legacy data is never modified or deleted and any failure falls back to
it, so the manifests keep --filesystem=~/.<app> to keep that fallback
readable. The -d launch flag still takes precedence over all of this.

closes #1249
The verified copy left a full second copy of the wallet data, password
and secure store in ~/.<app>. A desktop reset of the new root does not
touch it, so the old data survived a "forgot password" reset.

Rename the legacy root when possible. Otherwise (always the case inside
Flatpak, where it is a bind mount) remove its contents once the copy is
verified and in place. A marker written first lets the next launch finish
an interrupted removal; legacy data written after a completed migration
without that marker is left alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flatpak: .stackwallet inside the sandbox

2 participants